package org.xiji.observer;

import java.util.Scanner;

/**
 * 观察者模式
 */
public class ObserverMain {
    /**
     * 主函数
     */
    public static void main(String[] args) {
        //创建客户端
        ObserverImpl observer = new ObserverImpl();
        observer.setName("张三");
        //创建客户端
        ObserverImpl observer2 = new ObserverImpl();
        observer2.setName("李四");
        //创建客户端
        ObserverImpl observer3 = new ObserverImpl();
        observer3.setName("小久");

        //创建主题
        SubjectImpl subject = new SubjectImpl();
        subject.setState("1");
        //创建接受键盘数据的变量
        Scanner input = new Scanner(System.in);

        //注册进去
        subject.register(observer);
        subject.register(observer2);
        subject.register(observer3);



        while (true) {
            System.out.println("请发布主题消息");


            subject.setState(input.nextLine());


        }

    }
}
